﻿using ClientAppraise.Controls;
using ClientAppraise.ViewModels.Pages.Users;
using ClientAppraise.Views.Pages;
using ClientAppraise.Views.Pages.Users;
using ClientAppraise.Views.Pages.Users.Org;
using ClientAppraise.Views.Pages.Users.Org.Admin;
using ClientInfrastructure.Model;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace ClientAppraise.ViewModels.Pages
{
    public partial class MainWindowViewModel : ObservableObject
    {
        [ObservableProperty]
        protected string? _applicationTitle;

        [ObservableProperty]
        private ObservableCollection<ZxNavigationViewItem> _menuItems = [];

        [ObservableProperty]
        private ICollection<object> _footerMenuItems = [
            new ZxNavigationViewItem("角色切换", SymbolRegular.Settings24, typeof(TestPage)),
            new ZxNavigationViewItem("Settings", SymbolRegular.Settings24, typeof(TestPage))
        ];

        [ObservableProperty]
        private ObservableCollection<Wpf.Ui.Controls.MenuItem> _trayMenuItems = [
            new Wpf.Ui.Controls.MenuItem { Header = "Home", Tag = "tray_home" },
            new Wpf.Ui.Controls.MenuItem { Header = "Close", Tag = "tray_close" }
            ];


        public void TestMenu()
        {
            MenuItems.Add(new ZxNavigationViewItem("11", SymbolRegular.Grid20, typeof(TestPage)));//No changes to navigation
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="role">企业用户，企业管理员，管理员</param>
        /// <returns></returns>
        public ObservableCollection<ZxNavigationViewItem> GetMenuItemsByAuth(int role)
        {
            //ControlTemplate controlTemplate = App.GetRequiredService<INavigationService>()?.GetNavigationControl().ItemTemplate;

            List<ZxNavigationViewItem> Fun(List<NavigationViewItemWithAuth> sonItem)
            {
                var rere = new List<ZxNavigationViewItem>();
                foreach (var item in sonItem)
                {
                    if (true)//这句以后要改为真实判断
                    {
                        var obj = new ZxNavigationViewItem
                        {
                            Content = item.Name,
                          //  Visibility = item.IsNavigation ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed,
                        };


                        if (!string.IsNullOrEmpty(item.Icon))
                        {
                            if (item.IsSymbolRegularIcon)
                            {
                                SymbolRegular icon = (SymbolRegular)Enum.Parse(typeof(SymbolRegular), item.Icon);
                                obj.Icon = new SymbolIcon(icon);
                            }
                            else
                            {
                                ZxAliRegular icon = (ZxAliRegular)Enum.Parse(typeof(ZxAliRegular), item.Icon);
                                obj.Icon = new ZxAliFontIcon(icon);
                            }
                        }

                        if (item.TargetPageType != null)
                        {
                            obj.TargetPageType = item.TargetPageType;
                        }
                        else
                        {
                            if (item.Sons.Count > 0)
                            {
                                obj.MenuItems = Fun(item.Sons);
                                //var rerere = Fun(item.Sons);

                                //if (rerere != default && rerere.Count > 0)
                                //{
                                //    foreach (var item2 in rerere)
                                //    {
                                //        obj.MenuItems.Add(item2);
                                //    }
                                //}
                            }
                        }

                        rere.Add(obj);
                    }
                }

                return rere;
            }

            var nvItems = new List<ZxNavigationViewItem>();

            switch (role)
            {
                case 0:
                    {
                        nvItems = Fun(NavigationViewItems());
                        break;
                    }
                case 1:
                    {
                        nvItems = Fun(OrgAdminNavigationViewItems());
                        break;
                    }
                case 2:
                    {
                        nvItems = Fun(AdminNavigationViewItems());
                        break;
                    }
            }

            ObservableCollection<ZxNavigationViewItem> re = new(nvItems);

            return re;
        }


        public List<NavigationViewItemWithAuth> AdminNavigationViewItems()
        {
            var re = new List<NavigationViewItemWithAuth>
            {
                new(0, "企业管理", "Grid20",[
                    new NavigationViewItemWithAuth(0, "企业列表", "Grid20",typeof(IndexPage))
                ]),
                new(0, "权限管理", "Grid20",[
                    new NavigationViewItemWithAuth(0, "接口列表", "Grid20",typeof(AdminIndexPage)),
                    new NavigationViewItemWithAuth(0, "功能列表", "Grid20",typeof(AdminIndexPage)),
                    new NavigationViewItemWithAuth(0, "角色列表", "Grid20",typeof(AdminIndexPage)),
                ]),
                new(0, "语料管理", "Grid20", [
                    new NavigationViewItemWithAuth(0, "语料分类", "Grid20",typeof(Views.Pages.Corpus.CorpusType.Admin.IndexPage)),
                    new NavigationViewItemWithAuth(0, "装饰分类", "Grid20",typeof(Views.Pages.Corpus.CorpusType.Admin.IndexPage)),
                    new NavigationViewItemWithAuth(0, "语料装饰", "Grid20",typeof(Views.Pages.Corpus.CorpusAdorn.Admin.IndexPage)),
                    new NavigationViewItemWithAuth(0, "语料版本", "Grid20",typeof(Views.Pages.Corpus.CorpusVersion.Admin.IndexPage)),
                    new NavigationViewItemWithAuth(0, "语料库", "Grid20",typeof(TestPage)),
                ]),
                new(0, "企业管理0", "Grid20", [
                    new NavigationViewItemWithAuth(0, "企业管理2", "Grid20",typeof(TestPage))

                ])
            };

            return re;
        }
        public List<NavigationViewItemWithAuth> OrgAdminNavigationViewItems()
        {
            var re = new List<NavigationViewItemWithAuth>
            {
                new(0, "超级管理", "Grid20", [
                        new NavigationViewItemWithAuth(0, "接口列表", "Grid20",typeof(AdminIndexPage)),
                        new NavigationViewItemWithAuth(0, "功能列表", "Grid20",typeof(AdminIndexPage)),
                        new NavigationViewItemWithAuth(0, "角色列表", "Grid20",typeof(AdminIndexPage)),
                ]),
                new(0, "企业管理", "Grid20", [
                    new NavigationViewItemWithAuth(0, "企业管理2", "Grid20",typeof(TestPage))

                ]),
                new(0, "企业管理0", "Grid20", [
                    new NavigationViewItemWithAuth(0, "企业管理2", "Grid20",typeof(TestPage))

                ])
            };

            return re;
        }

        public List<NavigationViewItemWithAuth> NavigationViewItems()
        {
            var re = new List<NavigationViewItemWithAuth>
            {
                new(0, "超级管理", "Grid20", [
                        new NavigationViewItemWithAuth(0, "企业列表", "Grid20",typeof(AdminIndexPage))
                ]),
                new(0, "企业管理", "Grid20", [
                    new NavigationViewItemWithAuth(0, "企业管理2", "Grid20",typeof(TestPage))

                ]),
                new(0, "企业管理0", "Grid20", [
                    new NavigationViewItemWithAuth(0, "企业管理2", "Grid20",typeof(TestPage))

                ])
            };

            return re;
        }

    }
}
